<%--
  Created by IntelliJ IDEA.
  User: dqf
  Date: 2015/3/2
  Time: 15:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<style>
    .createBtn{
        margin-top:6px;
        margin-bottom:10px
    }
    ul#sparks li a{
        cursor:pointer
    }
</style>
<div class="row">
    <div class="row" style="opacity: 1;border-bottom: 1px solid #dee4e8;">
        <div class="row">
            <div class="col-lg-3 col-sm-7 col-xs-28">
                <div id="ajax_client-list" class="main-box infographic-box colored emerald-bg" style="margin-left: 8px;">
                    <i class="fa fa-linkedin-square"></i>
                    <span class="headline">客戶信息</span>
                    <span class="value">&nbsp;<s:property value="businessData.client"/></span>
                    <input type="hidden" id="selectedIds" value=""/>
                </div>
            </div>

            <div class="col-lg-3 col-sm-7 col-xs-28">
                <div id="ajax_linkman-list" class="main-box infographic-box colored green-bg">
                    <i class="fa fa-user"></i>
                    <span class="headline">联系人信息</span>
                    <span class="value">&nbsp;<s:property value="businessData.link"/></span>
                </div>
            </div>

            <div class="col-lg-3 col-sm-7 col-xs-28">
                <div id="ajax_proInfo-list" class="main-box infographic-box colored red-bg">
                    <i class="fa fa-book"></i>
                    <span class="headline">项目信息</span>
                    <span class="value">&nbsp;<s:property value="businessData.proInfo"/></span>
                </div>
            </div>

            <div class="col-lg-3 col-sm-7 col-xs-28">
                <div id="ajax_feedback-list" class="main-box infographic-box colored purple-bg" style="margin-right: 8px;">
                    <i class="fa fa-pencil-square-o"></i>
                    <span class="headline">反馈信息</span>
                    <span class="value">&nbsp;<s:property value="businessData.proBack"/></span>
                </div>
            </div>
        </div>

    </div>
    <div id="business_data">
        <div class="row createBtn">
            <div class="col-sm-12 col-md-12 col-lg-12">
                <div >
                    <shiro:hasAnyRoles name="wechat">
                        <form id="searchForm" method="post" action="">
                            <a id="ajax_client_btn_add" class="btn btn-default table_head_btn_left" data-toggle="modal"><i class="fa fa-lg fa-plus"></i> 新建客户信息表</a>
                            <a id="ajax_download_client_datas" class="btn btn-default pull-right" href="javascript:void(0);"> <i class="fa fa-lg fa-hand-o-right"></i> 进入下载中心 </a>
                            <a id="ajax_export_client_datas" class="btn btn-default pull-right" href="javascript:void(0);" style="margin-right: 5px;"><i class="fa fa-lg fa-external-link"></i> 客户信息数据导出 </a>
                        </form>
                    </shiro:hasAnyRoles>
                </div>
            </div>
        </div>
        <section id="widget-grid" class="">

            <!-- row -->
            <div class="row">
                <!-- NEW WIDGET START -->
                <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

                    <!-- Widget ID (each widget will need unique ID)-->
                    <div class="jarviswidget " id="wid-id-0" data-widget-editbutton="false"
                         data-widget-colorbutton="false"
                         data-widget-togglebutton="false"
                         data-widget-deletebutton="false"
                         data-widget-fullscreenbutton="true"
                         data-widget-custombutton="false"
                         data-widget-sortable="false">

                        <%--<header>--%>
                        <%--<span class="widget-icon"> <i class="fa fa-table"></i> </span>--%>
                        <%--<h2>客户信息列表</h2>--%>
                        <%--</header>--%>

                        <!-- widget div-->
                        <div>

                            <!-- widget edit box -->
                            <div class="jarviswidget-editbox">
                                <!-- This area used as dropdown edit box -->

                            </div>
                            <!-- end widget edit box -->

                            <!-- widget content -->
                            <div class="widget-body no-padding">

                                <div class="col-sm-12 col-md-12 col-lg-12">
                                    <div >
                                        <div class="row" id="ajax_client_list_row">
                                            <table id="ajax_client_table" class="table table-striped table-bordered table-hover">
                                            </table>
                                            <div id="ajax_client_list_page">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- end widget content -->

                        </div>
                        <!-- end widget div -->

                    </div>
                    <!-- end widget -->

                </article>
                <!-- WIDGET END -->

            </div>

            <!-- end row -->

            <!-- end row -->

        </section>
    </div>


    <script type="text/javascript">
        // DO NOT REMOVE : GLOBAL FUNCTIONS!
        pageSetUp();
        function client_reload(){
            loadURL("ajax!client.action",$('#content'));
        }
        $("#ajax_client_btn_add").click(function(){
            loadURL("ajax-client!input.action",$('div#business_data'));
        });

    </script>
        <script type="text/javascript">
            pageSetUp();
            $(function(){
                load_client_jqGrid();
            });
            function load_client_jqGrid(){
                jQuery("#ajax_client_table").jqGrid({
                    url:'ajax-client!list.action',
                    datatype: "json",
                    colNames:['客户名称',"客户简称",'客户性质',"所在区域","创建日期","操作","id"],
                    colModel:[
                        {name:'name',index:'name', width:120,search:true,sortable:true,
                            searchoptions:{sopt: ["cn"],clearSearch:true}},
                        {name:'subname',index:'subName', width:80,sortable:true,search:false},
                        {name:'type',index:'type', width:80,search:false},
                        {name:'area',index:'province', search:false,width:200},
                        {name:'createDate',index:'createDate', search:false,width:80},
                        {name:'act',index:'act', width:210,sortable:false,search:false,fixed:true},
                        {name:'id',index:'id',search:false,hidden:true},
                    ],
                    rowNum : 10,
                    rowList:[10,20,30],
                    pager : '#ajax_client_list_page',
                    sortname : 'createDate',
                    sortorder : "desc",
                    gridComplete:function(){

                        var ids=$("#ajax_client_table").jqGrid('getDataIDs');
                        var selectedIds = $("#selectedIds").val();
                        for(var i=0;i<ids.length;i++){
                            var cl=ids[i];
                            if (selectedIds != "" && selectedIds != null){
                                var idsArr = selectedIds.split(",");
                                for (var s=0;s<idsArr.length;s++){
                                    if (idsArr[s] == cl){
                                        $("#ajax_client_table").jqGrid("setSelection", cl);
                                    }
                                    // break;
                                }
                            }
                            var rowData = $("#ajax_client_table").jqGrid("getRowData",cl);
                            var de="<button class='btn btn-default' data-original-title='查看' onclick=\"fn_client_read('"+cl+"');\"><i class='fa fa-eye'></i>查看</button>"+" ";
                            var dt="<button class='btn btn-default' data-original-title='删除' onclick=\"fn_client_destroy('"+cl+"');\"><i class='fa fa-eye'></i>删除</button>"+" ";
                            if($("#ajax_client_btn_add").length==0){
                                dt="";
                            }
                            jQuery("#ajax_client_table").jqGrid('setRowData',ids[i],{act:de+dt});
                        }

                        $(".ui-jqgrid-bdiv").css("overflow-x","hidden");

                        jqGridStyle();

                    },
                    onSelectRow: function (rowId, status, e) {
                        var ids = $("#selectedIds").val();
                        if (ids != ""){
                            var idsArr = ids.split(",");
                            var isSelected = false;
                            for (var i=0; i<idsArr.length;i++){
                                if (idsArr[i] == rowId){
                                    isSelected = true;
                                    break;
                                }
                            }
                            if (status){
                                if (!isSelected)
                                    $("#selectedIds").val(ids + "," +rowId);
                            }
                            else{
                                if (isSelected) {
                                    if (idsArr.length < 2){
                                        $("#selectedIds").val("");
                                    }
                                    else{
                                        for (var i = 0; i < idsArr.length; i++) {
                                            if (idsArr[i] == rowId) {
                                                for (var j = i; j < idsArr.length - 1; j++) {
                                                    idsArr[j] = idsArr[j + 1];
                                                }
                                                idsArr.length = idsArr.length - 1;
                                                break;
                                            }
                                        }
                                        $("#selectedIds").val(idsArr.join(","));
                                    }
                                }
                            }
                        }
                        else{
                            $("#selectedIds").val(rowId);
                        }

                    },
                    onSelectAll:function(aRowids, status, e){
                        var ids = $("#selectedIds").val();
                        if (ids != "") {
                            var idsArr = ids.split(",");
                            for (var i = 0; i < aRowids.length; i++) {
                                var isSelected = false;
                                var index = -1;
                                for (var j = 0; j < idsArr.length; j++) {
                                    if (aRowids[i] == idsArr[j]) {
                                        isSelected = true;
                                        index = j;
                                        break;
                                    }
                                }
                                if (status) {
                                    if (!isSelected) {
                                        idsArr.push(aRowids[i]);
                                    }
                                }
                                else {
                                    if (isSelected) {
                                        for (var n = index; n < idsArr.length - 1; n++) {
                                            idsArr[n] = idsArr[n + 1];
                                        }
                                        idsArr.length = idsArr.length - 1;
                                    }
                                }
                            }
                            $("#selectedIds").val(idsArr.join(","));
                        }
                        else{
                            $("#selectedIds").val(aRowids.join(","));
                        }
                    },
                    jsonReader: {
                        root: "dataRows",
                        page: "page",
                        total: "total",
                        records: "records",
                        repeatitems : false
                    },
                    caption : "<i class='fa fa-arrow-circle-right'></i> 客户列表",
                    multiselect : true,
                    rownumbers:true,
                    gridview:true,
                    shrinkToFit:true,
                    viewrecords: true,
                    autowidth: true,
                    height:'auto',
                    forceFit:true,
                    loadComplete: function() {
                    }
                });
                $(window).on('resize.jqGrid', function() {
                    jQuery("#ajax_client_table").jqGrid('setGridWidth', $("#ajax_client_list_row").width());
                });
                jQuery("#ajax_client_table").jqGrid('filterToolbar',{searchOperators:false,stringResult:true});
                jQuery("#ajax_client_table").jqGrid('navGrid', "#ajax_client_list_page", {
                    edit : false,
                    add : false,
                    del : false,
                    search:false
                });
            }

            function fn_client_read(id){
                loadURL("ajax-client!read.action?keyId="+id,$('div#business_data'));
            }

            function fn_client_destroy(id){
                var vActionUrl = "<%=path%>/com/ajax-client!delete.action";
                data={keyId:id};
                ajax_action(vActionUrl,data,{},function(pdata){
                    _show(pdata);

                });

                jQuery("#ajax_client_table").trigger("reloadGrid");
                return;
            }
            $("#ajax_export_proInfo_datas").click(function(){
                if($("#selectedIds").val()==""){
                    var data = {
                        state:400,
                        title:"操作状态",
                        message:"请先勾选需要导出的联系人信息"
                    }
                    _show(data);
                    return;
                }
                $.SmartMessageBox({
                    title : "确定导出联系人信息数据吗？",
                    content : "确定导出操作将进入创建导出文件队列，进入下载中心可查看导出文件执行情况。",
                    buttons : '[取消][确认]'
                }, function(ButtonPressed) {
                    if (ButtonPressed === "确认") {
                        var idList=$("input#selectedIds").val();
						
						// location.href = "ajax-import!exportData.action?keyId=client&idList="+idList;
                       /* ajax_action("ajax-import!exportData.action?keyId=client"+"&idList="+idList,null,{},function(pdata){
                            _show(pdata);
                        });*/
                    }
                });

            });

            $("#ajax_download_proInfo_datas").click(function(){
                loadURL("ajax!downloadFile.action",$("#content"));
            });
        </script>

    <script type="text/javascript">

        $(function(){
            $("#ajax_client-list").click(function(){
                client_reload();
                //loadURL("ajax-client!list.action",$('div#business_data'));
            });
            $("#ajax_linkman-list").click(function(){
                loadURL("ajax-linkman!show.action",$('div#business_data'));
            });
            $("#ajax_proInfo-list").click(function(){
                loadURL("ajax-project!view.action",$('div#business_data'));
            });
            $("#ajax_feedback-list").click(function(){
                loadURL("ajax-pro-back!view.action",$('div#business_data'));
            });

        });

        $("#ajax_download_client_datas").click(function(){
            loadURL("ajax!downloadFile.action",$("#content"));
        });

        $("#ajax_export_client_datas").click(function(){
            //var ids = $("#ajax_client_table").jqGrid('getGridParam','selarrrow');
            if($("#selectedIds").val()==""){
                var data = {
                    state:400,
                    title:"操作状态",
                    message:"请先勾选需要导出的客户信息"
                }
                _show(data);
                return;
            }
            else{
                $.SmartMessageBox({
                    title : "确定导出客户信息数据吗？",
                    content : "确定导出操作将进入创建导出文件队列，进入下载中心可查看导出文件执行情况。",
                    buttons : '[取消][确认]'
                }, function(ButtonPressed) {
                    if (ButtonPressed === "确认") {
						location.href = "ajax-import!exportData.action?keyId=client&idList="+$("#selectedIds").val();
						/*
                        ajax_action("ajax-import!exportData.action?keyId=client&idList="+$("#selectedIds").val(),null,{},function(pdata){
                            _show(pdata);
                        });
						*/
                    }
                });
            }


        });
    </script>
